﻿/*
    This file is part of News Worm.

    News Worm is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    News Worm is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with News Worm.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Linq;
using System.IO;
using System.Windows.Forms;

namespace NewsWorm {
    static class Program {
        [STAThread]
        static void Main( string[] args ) {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault( false );

            string path = Environment.GetEnvironmentVariable( "APPDATA" ) + "\\NewsWorm\\";
            Variables.BasePath = path;

            if ( !Directory.Exists( path ) )
                Directory.CreateDirectory( path );

            bool exists = System.Diagnostics.Process.GetProcessesByName( 
                System.IO.Path.GetFileNameWithoutExtension( 
                System.Reflection.Assembly.GetEntryAssembly().Location ) ).Count() > 1;

            if ( exists ) {
                MessageBox.Show( "Another instance of News Worm is already running. Try again in a moment." );
            } else {
                if ( args.Length == 1 ) {
                    string url = args[0];
                    Application.Run( new MainWindow( path, url ) );
                } else {
                    Application.Run( new MainWindow( path ) );
                }
            }

        }
    }
}
